#include "../Entity_h/user.h"
#include "Error_h/error.h"
#include "../Net_h/NetAsyncImp.h"
#include "../VoicePlayer_h/VoicePlayerImp.h"
#include <QDebug>

User::User(){
    UserInfo info;
    _userInfo = info;                  //使用默认信息
    _userSocket = new NetAsyncImp();
    _userVoicePlayer = new VoicePlayerImp();
}

User::User(UserInfo userInfo){
    _userInfo = userInfo;
    _userSocket = new NetAsyncImp();
}

int User::ConnectServer(){
   return _userSocket->Connect(_serverIp,_serverPort);
}

int User::SendMessage(QString content){
    qDebug()<<"发送消息。。。";

    if(!_userSocket->IsConnected()) {
        _userSocket->Connect(_serverIp,_serverPort);
    }
    _userSocket->Send(content);
    return NONE;
}

void User::ReadMessage() const{
    qDebug()<<"User收到消息:"+_userSocket->GetMessage();
    emit InformUI();

}

void User::SetServer(QString serverIp, QString serverPort){
    _serverIp = serverIp;
    _serverPort = serverPort;
    connect(_userSocket,SIGNAL(NewMessageCame()),this,SLOT(ReadMessage()));

}

void User::SetFilePath(QString newFilePath){
    _userVoicePlayer->SetFilePath(newFilePath);
}

QString User::GetMessage(){
    return _userSocket->GetMessage();
}

void User::Play(){
    _userVoicePlayer->Play();
}

void User::Record(){
    _userVoicePlayer->Record();
}

void User::Finish(){
    _userVoicePlayer->Finish();
}
